//////////////////////////////////////////////////////////////////////////
/// Copyright (c) 2011, Sidorenko 'PC' Alexander                       ///
/// mailto: sidorenko /*dot*/ alexander (at) gmail [dot] com           ///
/// This file is a part of the Radiating Gas Dynamics project          ///
//////////////////////////////////////////////////////////////////////////

#pragma once

class CTimelineListener
{
public:

	virtual void OnTimeChanged(gdScalar factor) = 0;
	virtual void OnPlotTypeChanged() = 0;

};

class Problem;
class CColorBar;

// CTimeline dialog
class CTimeline : public CDialog
{
	DECLARE_DYNAMIC(CTimeline)

public:
	CTimeline(CWnd* pParent = NULL);   // standard constructor
	virtual ~CTimeline();

	void setProblem(Problem *pr);

	void PlotCurrentSolution(CDC& dc, const CRect& rect, const CColorBar& color);

	inline unsigned int GetNumTimesteps() const { return m_numTimesteps; }
	inline gdScalar GetPlaybackTime() const { return m_playbackTime; }

	inline void setLisneter(CTimelineListener *pL) { m_pListener = pL; }

// Dialog Data
	enum { IDD = IDD_TIMELINE };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnBnClickedPlay();
	afx_msg void OnBnClickedLooped();
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

	DECLARE_MESSAGE_MAP()

private:

	void SetNumTimesteps(unsigned int numSteps);
	void SetPlaybackTime(gdScalar time);

	void ResizeTimeline();

	void Pause();
	void Play();

	unsigned int getCurPlotStep() const;

	void SetCutStep(unsigned int step);

	Problem *m_pCurProblem;

	CTimelineListener *m_pListener;
	unsigned int m_numTimesteps;
	gdScalar m_playbackTime;

	bool m_bPlaying;

	int m_step;
	gdScalar m_floatStep;
	unsigned int m_prevTick;
	BOOL m_looped;

	int m_plotType;
public:
	afx_msg void OnCbnSelchangePlotType();
};
